﻿using Paperless.Entities;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using System.Web;

namespace Paperless.Repositories
{
    public class NoteRepository : BaseRepository<Note>
    {
        public override async Task<int> Add(Note entity)
        {
            using (var context = Context)
            {
                for (int i = 0; i < entity.Agents.Count; i++)
                {
                    var id = entity.Agents[i].Id;
                    entity.Agents[i] = context.Agents.FirstOrDefault(x => x.Id == id);
                }

                context.Set<Note>().Add(entity);

                return await context.SaveChangesAsync();
            }
        }
    }
}